<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Think;
use Think\Auth;
class BulletinController extends Controller {
    /**
     * 公告列表页面
     * @author yzc 562608962@qq.com
     */   
    function Bulletin(){
        $bulletin = M('bulletin');
        $info=$bulletin->select();
        $this->assign("info",$info);
    	$this->display();
    }
    /**
     * 公告添加
     * @author yzc 562608962@qq.com
     */   
    function Bulletin_add(){
        $bulletin = M('bulletin');
        if(IS_POST){
            $_POST["status"]=0;
            $_POST["CreateTime"]=date("Y-m-d H:i:s");
            $_POST["createUser"]=M("users")->getFieldByID($_SESSION["id"],'name');
            $res=$bulletin->add($_POST);
            if($res>= 0){
                $this->ajaxreturn('success');
            }else{
                $this->ajaxreturn('error');
            }
        }
        $this->display();
    }
    /**
     * 公告删除
     * @author yzc 562608962@qq.com
     */   
    function Bulletin_del(){
        if($_POST){
            $id=$_POST["id"];
            if(is_array($id)){
                foreach ($id as $key => $value) {
                    $res=M("bulletin")->where("id=".$value)->delete();  
                }
                if($res){
                    $this->ajaxreturn("已删除");
                }else {
                    $this->ajaxreturn("error");
                }
            }else{
                $bulletin = M('bulletin');
                $res=$bulletin ->where($_POST)->delete();
                if($res){
                    $this->ajaxreturn("已删除");
                }else {
                    $this->ajaxreturn("error");
                }
            }
        }
    }
    /**
     * 公告编辑
     * @author yzc 562608962@qq.com
     */   
    function Bulletin_edit(){
        if($_GET){
            $id["id"]=$_GET["id"];
            if(IS_POST){
                $res=M("bulletin")->where($id)->save($_POST);
                if($res>= 0){
                    $this->ajaxreturn('success');
                }else{
                    $this->ajaxreturn('error');
                }
            }
            $info=M("bulletin")->where($id)->find();
            $this->assign("info",$info);
            $this->display();
        }
    }
    /**
     * 公告发布
     * @author yzc 562608962@qq.com
     */   
    function Bulletin_up(){
        if($_GET){
            $id["id"]=$_GET["id"];
            $data["status"]=1;
            $data["Auditor"]=M("users")->getFieldByID($_SESSION["id"],'name');
            $data["AudTime"]=date("Y-m-d H:i:s");
            $res=M("bulletin")->where($id)->save($data);
            if($res){
                $this->success("已发布",U("Bulletin"));
            }else{
                $this->error("error",U("Bulletin"));
            }
        }
    }
    /**
     * 公告撤销
     * @author yzc 562608962@qq.com
     */   
    function Bulletin_down(){
        if($_GET){
            $id["id"]=$_GET["id"];
            $data["status"]=2;
            $data["undoUser"]=M("users")->getFieldByID($_SESSION["id"],'name');
            $data["undoTime"]=date("Y-m-d H:i:s");
            $res=M("bulletin")->where($id)->save($data);
            if($res){
                $this->success("已撤销",U("Bulletin"));
            }else{
                $this->error("error",U("Bulletin"));
            }
        }
    }
 }
